package com.java.exer1;

import java.util.Arrays;

/**
 * 去除字符串中的空格，仿照trim（）方法
 *
 * @author shkstart
 * @create 2021-01-05 21:50
 */
public class StringTest_2 {
    public static void main(String[] args) {
        String a = " 1 2 3 ";
        char[] b = a.toCharArray();
        int count = 0;
        int i;
        for (i = 0; i < b.length; i++) {
            if (b[i] != ' ') {
                count++;
                System.out.println(count);
            }
        }
        char[] c = new char[count];
        for (int j = 0; j < count; j++) {
            c[j] = b[j];
        }
        System.out.println(Arrays.toString(c));
        String d = new String(b);
    }
}
